using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
    /// <summary>
    /// Controller class for CX_Apply
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class CxApplyController
    {
        // Preload our schema..
        CxApply thisSchemaLoad = new CxApply();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public CxApplyCollection FetchAll()
        {
            CxApplyCollection coll = new CxApplyCollection();
            Query qry = new Query(CxApply.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public CxApplyCollection FetchByID(object Id)
        {
            CxApplyCollection coll = new CxApplyCollection().Where("ID", Id).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public CxApplyCollection FetchByQuery(Query qry)
        {
            CxApplyCollection coll = new CxApplyCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object Id)
        {
            return (CxApply.Delete(Id) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object Id)
        {
            return (CxApply.Destroy(Id) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int? Uid,Guid? Guid,string Reason,string Tbname,int? CountTimes,int? Status,DateTime? InTime,int? BossID,int? BossNod,DateTime? BossTime,DateTime? UserTime)
	    {
		    CxApply item = new CxApply();
		    
            item.Uid = Uid;
            
            item.Guid = Guid;
            
            item.Reason = Reason;
            
            item.Tbname = Tbname;
            
            item.CountTimes = CountTimes;
            
            item.Status = Status;
            
            item.InTime = InTime;
            
            item.BossID = BossID;
            
            item.BossNod = BossNod;
            
            item.BossTime = BossTime;
            
            item.UserTime = UserTime;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int Id,int? Uid,Guid? Guid,string Reason,string Tbname,int? CountTimes,int? Status,DateTime? InTime,int? BossID,int? BossNod,DateTime? BossTime,DateTime? UserTime)
	    {
		    CxApply item = new CxApply();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.Id = Id;
				
			item.Uid = Uid;
				
			item.Guid = Guid;
				
			item.Reason = Reason;
				
			item.Tbname = Tbname;
				
			item.CountTimes = CountTimes;
				
			item.Status = Status;
				
			item.InTime = InTime;
				
			item.BossID = BossID;
				
			item.BossNod = BossNod;
				
			item.BossTime = BossTime;
				
			item.UserTime = UserTime;
				
	        item.Save(UserName);
	    }
    }
}
